import sys

import pymysql
from apscheduler.schedulers.background import BackgroundScheduler

sys.path.extend(["F:/ML/BNC", "D:/BNC", "/www/wwwroot/BNC"])
from DataBase import DatabaseConsts

# class DBConnection:
#     host = '192.168.0.199'
#     # host = '127.0.0.1'
#     port = 3306
#     db = DatabaseConsts.StockDdataOverDB
#     user = 'root'
#     # password = 'h303567469'
#     password = 'root'
#
#     def __init__(self, db, host=host, port=port, user=user, passwd=password, charset='utf8',
#                  cursor_type=pymysql.cursors.DictCursor):
#         self.connection = pymysql.connect(host=host,
#                                           port=int(port),
#                                           user=user,
#                                           password=passwd,
#                                           db=db,
#                                           charset='utf8')
#         self.cursor = self.connection.cursor(cursor=cursor_type)
#
#         def keep_connection(self):
#             print("args :{}".format(self))
#             sql = " select 1 ;"
#             self.cursor.execute(sql)
#             self.cursor.fetchall()
#             print("keep connection ")
#             # 初始化 sched 模块的 scheduler 类
#
#         scheduler = BackgroundScheduler()
#         # 添加调度任务
#         # 调度方法为 timedTask，触发器选择 interval(间隔性)，间隔时长为 2 秒
#         scheduler.add_job(keep_connection, trigger='interval', args=(self,), seconds=60*60*5)
#         # 启动调度任务
#         scheduler.start()
#
#     @staticmethod
#     def get_mysql_db_uri(host,
#                          user,
#                          password,
#                          db,
#                          port=3306,
#                          charset='utf8'):
#         db_uri = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8". \
#             format(username=user, password=password, host=host, port=port, db=db)
#         return db_uri
